import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class Prop1(QWidget):
    def __init__(self):
        super(Prop1, self).__init__()
        self.setWindowTitle('Prop2')

        self.super_parameter = {
            'speed': 10,
            'pitch': 10,
            'range': 10,
            'anger': 10,
            'sadness': 10,
            'joy': 10,
            'file_path': 'C://vro3',
            'selected': 2004
        }

        vros_group = QButtonGroup(self)

        label_akane = QLabel(self)
        label_aoi = QLabel(self)
        label_akane.setPixmap(QPixmap('../head/6.png'))
        label_aoi.setPixmap(QPixmap('../head/1.png'))

        kotonoha_imgs = QHBoxLayout()
        kotonoha_imgs.addWidget(label_akane)
        kotonoha_imgs.addWidget(label_aoi)

        radio_akane = QRadioButton('akane', self)
        radio_aoi = QRadioButton('aoi', self)
        vros_group.addButton(radio_akane)
        vros_group.addButton(radio_aoi)

        radio_akane.toggled.connect(lambda: self.select_vro(552))
        radio_aoi.toggled.connect(lambda: self.select_vro(551))

        radio_vro2 = QHBoxLayout()
        radio_vro2.addWidget(radio_akane)
        radio_vro2.addWidget(radio_aoi)
        radio_vro2_widget = QWidget()
        radio_vro2_widget.setLayout(radio_vro2)

        # next is vro2 attr anger
        self.anger_sl = QSlider(Qt.Vertical)
        self.anger_sl.setMinimum(0)
        self.anger_sl.setMaximum(10)
        self.anger_sl.setSingleStep(1)
        self.anger_sl.setValue(0)
        self.anger_sl.valueChanged.connect(self.change_anger_value)
        self.anger_label = QLabel('anger:0.0')
        anger_select_layout = QVBoxLayout()
        anger_select_layout.addWidget(self.anger_sl)
        anger_select_layout.addWidget(self.anger_label)
        anger_select_layout_widget = QWidget()
        anger_select_layout_widget.setLayout(anger_select_layout)

        # next is vro2 attr sadness
        self.sadness_sl = QSlider(Qt.Vertical)
        self.sadness_sl.setMinimum(0)
        self.sadness_sl.setMaximum(10)
        self.sadness_sl.setSingleStep(1)
        self.sadness_sl.setValue(0)
        self.sadness_sl.valueChanged.connect(self.change_sadness_value)
        self.sadness_label = QLabel('sad:0.0')
        sadness_select_layout = QVBoxLayout()
        sadness_select_layout.addWidget(self.sadness_sl)
        sadness_select_layout.addWidget(self.sadness_label)
        sadness_select_layout_widget = QWidget()
        sadness_select_layout_widget.setLayout(sadness_select_layout)

        # next is vro2 attr joy
        self.joy_sl = QSlider(Qt.Vertical)
        self.joy_sl.setMinimum(0)
        self.joy_sl.setMaximum(10)
        self.joy_sl.setSingleStep(1)
        self.joy_sl.setValue(0)
        self.joy_sl.valueChanged.connect(self.change_joy_value)
        self.joy_label = QLabel('joy:0.0')
        joy_select_layout = QVBoxLayout()
        joy_select_layout.addWidget(self.joy_sl)
        joy_select_layout.addWidget(self.joy_label)
        joy_select_layout_widget = QWidget()
        joy_select_layout_widget.setLayout(joy_select_layout)

        # vro2 attrs group
        vro2_attr_layout = QHBoxLayout()

        vro2_attr_layout.addWidget(anger_select_layout_widget)
        vro2_attr_layout.addWidget(sadness_select_layout_widget)
        vro2_attr_layout.addWidget(joy_select_layout_widget)
        vro2_attr_layout_widget = QWidget()
        vro2_attr_layout_widget.setLayout(vro2_attr_layout)

        kotonoha_imgs_widgt = QWidget()
        kotonoha_imgs_widgt.setLayout(kotonoha_imgs)

        vro2_imgs_and_sliders = QVBoxLayout()
        vro2_imgs_and_sliders.addWidget(kotonoha_imgs_widgt)
        vro2_imgs_and_sliders.addWidget(radio_vro2_widget)
        vro2_imgs_and_sliders.addWidget(vro2_attr_layout_widget)
        vro2_imgs_and_sliders_widget = QWidget()
        vro2_imgs_and_sliders_widget.setLayout(vro2_imgs_and_sliders)

        # add vro imgs
        label_yukari = QLabel(self)
        label_zunko = QLabel(self)
        label_seika = QLabel(self)
        label_kiritan = QLabel(self)
        label_maki = QLabel(self)
        label_akari = QLabel(self)
        # add labels

        label_yukari.setPixmap(QPixmap('../head/2.png'))
        #label_yukari.setSizePolicy(16, 16)
        label_zunko.setPixmap(QPixmap('../head/3.png'))
        label_seika.setPixmap(QPixmap('../head/4.png'))
        label_kiritan.setPixmap(QPixmap('../head/5.png'))
        label_maki.setPixmap(QPixmap('../head/7.png'))
        label_akari.setPixmap(QPixmap('../head/8.png'))
        # add images

        images2 = QHBoxLayout()
        images2.addWidget(label_yukari)
        images2.addStretch()
        images2.addWidget(label_zunko)
        images2.addStretch()
        images2.addWidget(label_seika)
        images2.addStretch()
        images2.addWidget(label_kiritan)
        images2.addStretch()
        images2.addWidget(label_maki)
        images2.addStretch()
        images2.addWidget(label_akari)
        images2.addStretch()
        # add images label into layout 'image2'

        images2_widget = QWidget()
        images2_widget.setLayout(images2)

        radio_yukari = QRadioButton('yukari', self)
        radio_zunko = QRadioButton('zunko', self)
        radio_seika = QRadioButton('seika', self)
        radio_kiritan = QRadioButton('kiritan', self)
        radio_maki = QRadioButton('maki', self)
        radio_akari = QRadioButton('akari', self)

        radio_yukari.toggled.connect(lambda: self.select_vro(1206))
        radio_zunko.toggled.connect(lambda: self.select_vro(1202))
        radio_seika.toggled.connect(lambda: self.select_vro(1208))
        radio_kiritan.toggled.connect(lambda: self.select_vro(1209))
        radio_maki.toggled.connect(lambda: self.select_vro(1025))
        radio_akari.toggled.connect(lambda: self.select_vro(554))

        vros_group.addButton(radio_yukari)
        vros_group.addButton(radio_zunko)
        vros_group.addButton(radio_seika)
        vros_group.addButton(radio_kiritan)
        vros_group.addButton(radio_maki)
        vros_group.addButton(radio_akari)

        radio_vro1 = QHBoxLayout()
        radio_vro1.addWidget(radio_yukari)
        radio_vro1.addWidget(radio_zunko)
        radio_vro1.addWidget(radio_seika)
        radio_vro1.addWidget(radio_kiritan)
        radio_vro1.addWidget(radio_maki)
        radio_vro1.addWidget(radio_akari)
        radio_vro1_widget = QWidget()
        radio_vro1_widget.setLayout(radio_vro1)

        self.speed_sl = QSlider(Qt.Horizontal)
        self.speed_sl.setMinimum(5)
        self.speed_sl.setMaximum(40)
        self.speed_sl.setSingleStep(1)
        self.speed_sl.setValue(10)
        self.speed_sl.valueChanged.connect(self.change_speed_value)
        self.pitch_sl = QSlider(Qt.Horizontal)
        self.pitch_sl.setMinimum(5)
        self.pitch_sl.setMaximum(20)
        self.pitch_sl.setSingleStep(1)
        self.pitch_sl.setValue(10)
        self.pitch_sl.valueChanged.connect(self.change_pitch_value)
        self.range_sl = QSlider(Qt.Horizontal)
        self.range_sl.setMinimum(0)
        self.range_sl.setMaximum(20)
        self.range_sl.setSingleStep(1)
        self.range_sl.setValue(10)
        self.range_sl.valueChanged.connect(self.change_range_value)

        self.speed_label = QLabel('speed:1.0')
        self.pitch_label = QLabel('pitch:1.0')
        self.range_label = QLabel('range:1.0')

        speed_select_layout = QHBoxLayout()
        speed_select_layout.addWidget(self.speed_sl)
        speed_select_layout.addWidget(self.speed_label)

        pitch_select_layout = QHBoxLayout()
        pitch_select_layout.addWidget(self.pitch_sl)
        pitch_select_layout.addWidget(self.pitch_label)

        range_select_layout = QHBoxLayout()
        range_select_layout.addWidget(self.range_sl)
        range_select_layout.addWidget(self.range_label)

        vro1_attr_layout = QVBoxLayout()
        speed_select_layout_widget = QWidget()
        pitch_select_layout_widget = QWidget()
        range_select_layout_widget = QWidget()
        speed_select_layout_widget.setLayout(speed_select_layout)
        pitch_select_layout_widget.setLayout(pitch_select_layout)
        range_select_layout_widget.setLayout(range_select_layout)

        vro1_attr_layout.addWidget(speed_select_layout_widget)
        vro1_attr_layout.addWidget(pitch_select_layout_widget)
        vro1_attr_layout.addWidget(range_select_layout_widget)
        vro1_attr_layout_widget = QWidget()
        vro1_attr_layout_widget.setLayout(vro1_attr_layout)

        trans_btn_en = QPushButton('en->ja')
        trans_btn_cn = QPushButton('cn->ja')

        btns = QVBoxLayout()
        btns.addWidget(trans_btn_en)
        btns.addWidget(trans_btn_cn)
        btns_widgt = QWidget()
        btns_widgt.setLayout(btns)
        # buttons in transform

        self.will_be_trans = QTextEdit()
        self.target_mess_to_read = QTextEdit()

        will_be_trans_and_trans_btns = QHBoxLayout()
        will_be_trans_and_trans_btns.addWidget(self.will_be_trans)
        will_be_trans_and_trans_btns.addWidget(btns_widgt)
        will_be_trans_and_trans_btns_widgt = QWidget()
        will_be_trans_and_trans_btns_widgt.setLayout(will_be_trans_and_trans_btns)
        main_message_panel = QVBoxLayout()
        main_message_panel.addWidget(will_be_trans_and_trans_btns_widgt)
        main_message_panel.addWidget(self.target_mess_to_read)

        trans_btn_en.clicked.connect(self.trans_en)
        trans_btn_cn.clicked.connect(self.trans_cn)
        main_message_panel_widget = QWidget()
        main_message_panel_widget.setLayout(main_message_panel)

        get_btn = QPushButton('GET')
        self.ogg_label = QRadioButton('.ogg')
        self.mp3_label = QRadioButton('.mp3')
        self.mp3_label.setChecked(True)
        file_name_layout = QVBoxLayout()
        file_name_layout.addWidget(self.ogg_label)
        file_name_layout.addWidget(self.mp3_label)

        self.select_path = QPushButton()
        self.select_path.setText('PAth')

        self.select_path.clicked.connect(self.ask_path)

        file_name_layout_widgt = QWidget()
        file_name_layout_widgt.setLayout(file_name_layout)
        get_btns_layout = QHBoxLayout()
        get_btns_layout.addWidget(file_name_layout_widgt)
        get_btns_layout.addWidget(self.select_path)
        get_btns_layout.addWidget(get_btn)
        get_btns_layout_widget = QWidget()
        get_btns_layout_widget.setLayout(get_btns_layout)

        get_btn.clicked.connect(self.get_audio)

        vro1_and_vro1_attr_and_trans = QVBoxLayout()
        vro1_and_vro1_attr_and_trans.addWidget(images2_widget)
        vro1_and_vro1_attr_and_trans.addWidget(radio_vro1_widget)
        vro1_and_vro1_attr_and_trans.addWidget(vro1_attr_layout_widget)
        vro1_and_vro1_attr_and_trans.addWidget(main_message_panel_widget)
        vro1_and_vro1_attr_and_trans.addWidget(get_btns_layout_widget)
        vro1_and_vro1_attr_and_trans_widget = QWidget()
        vro1_and_vro1_attr_and_trans_widget.setLayout(vro1_and_vro1_attr_and_trans)

        total_layout = QHBoxLayout()
        total_layout.addWidget(vro2_imgs_and_sliders_widget)
        total_layout.addWidget(vro1_and_vro1_attr_and_trans_widget)

        self.setLayout(total_layout)

    def change_speed_value(self):
        self.super_parameter['speed'] = self.speed_sl.value()
        self.speed_label.setText('speed:' + str(self.super_parameter['speed'] / 10.0))

    def change_pitch_value(self):
        self.super_parameter['pitch'] = self.pitch_sl.value()
        self.pitch_label.setText('pitch:' + str(self.super_parameter['pitch'] / 10.0))

    def change_range_value(self):
        self.super_parameter['range'] = self.range_sl.value()
        self.range_label.setText('range:' + str(self.super_parameter['range'] / 10.0))

    def change_anger_value(self):
        self.super_parameter['anger'] = self.anger_sl.value()
        self.anger_label.setText('anger:' + str(self.super_parameter['anger'] / 10.0))

    def change_sadness_value(self):
        self.super_parameter['sadness'] = self.sadness_sl.value()
        self.sadness_label.setText('sadness:' + str(self.super_parameter['sadness'] / 10.0))

    def change_joy_value(self):
        self.super_parameter['joy'] = self.joy_sl.value()
        self.joy_label.setText('joy:' + str(self.super_parameter['joy'] / 10.0))

    def trans_en(self):
        # print(1)
        english_mess = self.will_be_trans.toPlainText()
        japan_mess = english_mess
        # 暂时不翻译
        self.target_mess_to_read.setHtml("<font color='red'>" + japan_mess + "</font>")

    def trans_cn(self):
        # print(2)
        Chinese_mess = self.will_be_trans.toPlainText()
        japan_mess = Chinese_mess
        # 暂时不翻译
        self.target_mess_to_read.setHtml("<font color='red'>" + japan_mess + "</font>")

    def get_audio(self):
        print(self.ogg_label.isChecked())
        print(self.mp3_label.isChecked())

    def ask_path(self):
        file_path = QFileDialog.getExistingDirectory()
        if file_path != '':
            self.super_parameter['file_path'] = file_path

    def select_vro(self, num):
        self.super_parameter['selected'] = num
        print(self.super_parameter['selected'])


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myshow = Prop1()
    myshow.show()
    sys.exit(app.exec_())
